package com.lagou.springbootweb;

import com.lagou.springbootweb.config.DynamicConfigDatasource;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

@SpringBootApplication
public class SpringbootwebApplication {

    public static void main(String[] args) throws IOException {
        SpringApplication.run(SpringbootwebApplication.class, args);

        System.out.println("test druid.");

        String zookeeperAddress = "linux121";
        DynamicConfigDatasource datasource = DynamicConfigDatasource.create(zookeeperAddress);
        while (true) {
            int read = System.in.read();
            testDruid(datasource);
        }
    }

    public static void testDruid(DynamicConfigDatasource datasource) {

        Connection connection = null;
        try {
            connection = datasource.getConnection();
            ResultSet resultSet = connection.prepareStatement("select user()").executeQuery();

            while (resultSet.next()) {
                System.out.println("当前登录的用户:" +  resultSet.getString(1));
            }

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }

}
